package com.decent.text;

import com.alibaba.fastjson.JSON;
import org.apdplat.word.WordSegmenter;
import org.apdplat.word.segmentation.Word;

import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * @author 王雪杰
 * @date 2021/10/21 15:29
 */
public class WordTest {
    public static void automaticSelection(String title) {
        //移除停用词进行分词
        List<Word> list = WordSegmenter.seg(title);

        //保留停用词
        List<Word> lists = WordSegmenter.segWithStopWords(title);
        System.out.println("\ntitle:" + title);
        System.out.println("移除停用词:" + list.stream().map(Word::getText).collect(Collectors.joining(", ")));
        System.out.println("保留停用词:" + lists.stream().map(Word::getText).collect(Collectors.joining(", ")));

    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        //long start1 = System.currentTimeMillis();
        //WordTest.automaticSelection("个人觉得简单的一句话，word用时就挺久的");
        //long ent1 = System.currentTimeMillis();

        //System.out.println((ent1 - start1) / 1000 );
        while (true) {
            System.out.print("\ninput:");
            String text = input.nextLine();
            if ("qwer".equals(text)) {
                return;
            }
            long start = System.currentTimeMillis();
            WordTest.automaticSelection(text);
            long ent = System.currentTimeMillis();
            System.out.println("耗时:" + (ent - start) + "ms");
        }

    }
}
